package cn.comon.app.scan.test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class

GetApkInfo {

    public static void
//http://wenku.baidu.com/view/9bba351f0b4e767f5bcfce05.html
//    
//    
    main(String[] args) {
        String apkName =GetApkInfo.getApkName("F:\\appDownload\\2013-05-03\\03.apk","./src/");
        System.out.println(apkName);
    }
    public static String
    getApkName(String apkPath,String aaptPath)
    {
        String apkName =
        ""
        ;
        try
        {
            Runtime rt = Runtime.
            getRuntime
            ();
            String order = aaptPath +
            "aapt.exe"

            +

            " d badging \""

            + apkPath +

            "\""

            ;

            Process proc = rt.exec(order);

            InputStream inputStream = proc.getInputStream();

            BufferedReader bufferedReader =

            new

            BufferedReader(

            new

            InputStreamReader(inputStream,

            "UTF-8"

            ));

            String line =

            null

            ;

            while

            ((line = bufferedReader.readLine()) !=

            null

            ) {

                if

                (line.contains(

                "application:"

                )) {

                    String str1 =

                    line.substring(line.indexOf(

                    "'"

                    ) + 1);

                    String str2 = str1.substring(0,

                    str1.indexOf(

                    "'"

                    ));

                    System.

                    out

                    .println(str2);

                    break

                    ;

                }

            }

        }

        catch

        (Throwable e) {

            e.printStackTrace();

        }

        return

        apkName;

    }

}
